package org.chatty;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.LineUnavailableException;

/**
 *
 * Thread management refactored into ThreadedByter
 *
 * @author Brian Hammond
 *
 */
public class Recorder extends ThreadedByter {

	private RecordingSetup recordingSetup_;

	public Recorder() {
		super();
	}

	public Recorder( RecordingSetup recordingSetup, CallBack callBack ) {
		super();
		this.setRecordingSetup( recordingSetup );
		this.setCallBack( callBack );
	}

	//// 

	public void start_process() throws Exception {
		this.getRecordingSetup().open();
	}

	public int process_chunk( byte buffer[] ) throws Exception {
		return this.getRecordingSetup().readInto( buffer ); 
	}

	public void stop_process() throws Exception {
		this.getRecordingSetup().close(); 
	}

	//// boilerplate: 

	public RecordingSetup getRecordingSetup() throws LineUnavailableException {
		return (
			null == this.recordingSetup_ 
			? this.recordingSetup_ = new RecordingSetup()
			: this.recordingSetup_
		);
	}

	public void setRecordingSetup( RecordingSetup recordingSetup ) {
		this.recordingSetup_ = recordingSetup;
	}

};
